from django.contrib import admin

from .models import Prompt, AnalysisReport, ModelConfig, WorkFlow

from django.utils.html import format_html
from django.urls import reverse


# 可以选择性地定义资源类，如果有需要定制行为
class DefaultResource(admin.ModelAdmin):
    class Meta:
        abstract = True


@admin.register(ModelConfig)
class ModelConfigAdmin(admin.ModelAdmin):
    list_display = ('name', 'enabled')
    list_editable = ('enabled',)


@admin.register(WorkFlow)
class WorFlowAdmin(admin.ModelAdmin):
    list_display = ('name', 'is_visible',)
    list_editable = ('is_visible',)


@admin.register(Prompt)
class PromptAdmin(admin.ModelAdmin):
    list_display = ('name', 'is_visible')
    list_editable = ('is_visible',)


@admin.register(AnalysisReport)
class AnalysisReportAdmin(admin.ModelAdmin):
    list_display = (
        'title',
        'view_link',
        'report_type',
        'summary',
        'is_reviewed',
        'updated_at',
    )
    list_filter = ('report_type',)

    def view_link(self, obj):
        url = reverse('report_detail', args=[obj.id])
        return format_html('<a href="{}" target="_blank">查看</a>', url)

    view_link.short_description = '预览链接'
